import { stringify } from 'querystring';
import { getRepository } from 'typeorm';
import { User } from '../entity/User';

async function goLogin(username: string, password: string) {
  var userRepository = getRepository(User);
  let user = await userRepository.findOne({ username: username });
  if (user) {
    if (user.password === password) {
      return {
        success: true,
        message: '登录成功',
        token: user.token,
        userId: user.id
      };
    } else {
      return {
        success: false,
        message: '登录失败，请输入正确的用户名和密码',
      };
    }
  } else {
    return {
      success: false,
      message: '没有此用户',
    };
  }
}
module.exports = { goLogin };
